package com.tarena.lbs.activity.service.impl;

import com.tarena.lbs.activity.dao.repository.ActivityRepository;
import com.tarena.lbs.activity.pojo.po.ActivityPO;
import com.tarena.lbs.activity.pojo.vo.ActivityVO;
import com.tarena.lbs.activity.service.ActivityService;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityRepository activityRepository;

    @Override
    public ActivityPO getDetail(Integer id) {
        return activityRepository.getDetail(id);
    }

    @Override
    public PageResult<ActivityVO> pageList() {
        PageResult<ActivityVO> pageResult = new PageResult<>();
        List<ActivityVO> activityVOS = new ArrayList<>();
        BeanUtils.copyProperties(activityRepository.listActivity(), activityVOS);
        pageResult.setObjects(activityVOS);
        pageResult.setPageNo(1);
        pageResult.setPageSize(10);
        pageResult.setTotal((long) activityVOS.size());
        return pageResult;
    }
}
